package com.itheima.hello.TCP通信;

import com.itheima.hello.TCP通信.多客户端TCP通信.ServerReaderThread;

import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws Exception {
        System.out.println("服务端启动成功");
        //创建ServerSocket对象,同时为服务端注册端口号
        ServerSocket serverSocket = new ServerSocket(8888);

        while (true) {
                //使用ServerSocket对象，调用一个accept方法。等待客户端的连接请求
                Socket socket = serverSocket.accept();
                System.out.println(socket.getRemoteSocketAddress() + "上线了!");
            System.out.println("--------------------------------");
                //把这个客户端对应的socket通信管道,交给一个独立的线程负责处理
                new ServerReaderThread(socket).start();
            }
        }
    }

